package com.shen.jcbf.testutil;

import org.junit.Test;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class SortTest {

    public static void main(String[] args) {
        test001();
    }

    public static void test001() {
        System.out.println("-----");

        try {
            Date d1  = new Date();
            Thread.sleep(1000);
            Date d2 = new Date();
            System.out.println(d1.compareTo(d2));
            System.out.println(d1.compareTo(d1));
            System.out.println(d2.compareTo(d1));

            long diff = d2.getTime() - d1.getTime();

            System.out.println(diff);
            System.out.println(diff > 1000);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    @Test
    public void test002(){
        List<Person> personList = new ArrayList();
        personList.add(new Person("5","4","6"));
        personList.add(new Person("8","7","9"));
        personList.add(new Person("2","1","3"));
        personList.add(new Person("10",null,null));
        personList.add(new Person("10","5",null));
        personList.add(new Person("10",null,"5"));

        personList.stream().sorted((a,b) -> {
            if(!StringUtils.isEmpty(a.getStartTime()) && !StringUtils.isEmpty(b.getStartTime())){
                return a.getStartTime().compareTo(b.getStartTime());
            }/*else if () {

            }else if () {

            }else {

            }*/
            return 1;
        });

    }

    private class Person {
        private String id;
        private String startTime;
        private String endTime;

        public Person() {
        }

        public Person(String id, String startTime, String endTime) {
            this.id = id;
            this.startTime = startTime;
            this.endTime = endTime;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getStartTime() {
            return startTime;
        }

        public void setStartTime(String startTime) {
            this.startTime = startTime;
        }

        public String getEndTime() {
            return endTime;
        }

        public void setEndTime(String endTime) {
            this.endTime = endTime;
        }
    }

}
